import fs from 'fs';

fs.writeFile('./bbb.txt', 'hello world', {
    encoding: 'utf-8',
    flag: 'a+' 
   }, (err) => {
    console.log('写入文件结果:', err);
   });

const writeStream = fs.createWriteStream('./ccc.txt',{ flags: 'a' });

writeStream.on('open', (fd) => {
    console.log('文件被打开', fd);
});

writeStream.write('coderwhy');
writeStream.write('aaaa');
writeStream.write('bbbb', (err) => {
 console.log("写入完成:", err);
});

writeStream.on('finish', () => {
    console.log('写入完成了');
   });
   
   writeStream.on('close', () => {
    console.log('文件被关闭~');
   });
   
   writeStream.end('哈哈哈哈');